
import Modules.Account.MyAccounts;
import Modules.Activity.MyActivity;
import Modules.Contact.MyContacts;
import Modules.NavigationInfo;
import Modules.Opportunity.MyOpportunities;
import Modules.Search.BasicSearch;
import Modules.Task.MyTasks;

import com.desidea.common.MenuConstants;
import com.desidea.utils.DirtyChecker;
import com.desidea.utils.IDirtyChecker;

import mx.controls.Alert;

private function windowInitialized():void
{
}

private function windowCreated():void
{
	loadModule();
}

private var _ni:NavigationInfo;
public function get NavInfo():NavigationInfo{
	return _ni;
}
public function set NavInfo(value:NavigationInfo):void{
	_ni = value;
}

public function loadModule():void{
	
	// CODE FOR DIRTY CHECK
	if( DirtyChecker.getInstance().isDirty){
		if (DirtyChecker.getInstance().sourceContainer is IDirtyChecker){
			(DirtyChecker.getInstance().sourceContainer as IDirtyChecker).promptToSave();
		}else{
			Alert.show("Save & Proceed");
		}
		return;
	}else{
		DirtyChecker.getInstance().resetDirtyChecker();
	}

	if(this.data == null){
		Alert.show("NULL DATA");
		return;
	}

	this.removeAllChildren();

	switch(String(this.data.id)){
		case MenuConstants.MY_ACCOUNT:
			loadMyAccounts();
			break;
		case MenuConstants.MY_ACTIVITIES:
			loadMyActivities();
			break;
		case MenuConstants.MY_CONTACTS:
			loadMyContacts();
			break;
		case MenuConstants.MY_OPPORTUNITIES:
			loadMyOpportunities();
			break;
		case MenuConstants.MY_TASKS:
			loadMyTasks();
			break;
		case MenuConstants.BASIC_SEARCH:
			loadBasicSearch();
			break;
		default:
			break;
	}
}

private function loadMyAccounts():void{
	var detail:MyAccounts = new MyAccounts();
	detail.NavInfo = this.NavInfo;
	this.addChild(detail);
}

private function loadMyActivities():void{
	var detail:MyActivity = new MyActivity();
	detail.NavInfo = this.NavInfo;
	this.addChild(detail);
}

private function loadMyContacts():void{
	var detail:MyContacts = new MyContacts();
	detail.NavInfo = this.NavInfo;
	this.addChild(detail);
}

private function loadMyOpportunities():void{
	var detail:MyOpportunities = new MyOpportunities();
	detail.NavInfo = this.NavInfo;
	this.addChild(detail);
}

private function loadMyTasks():void{
	var detail:MyTasks = new MyTasks();
	detail.NavInfo = this.NavInfo;
	this.addChild(detail);
}

private function loadBasicSearch():void{
	var detail:BasicSearch = new BasicSearch();
	this.addChild(detail);
}
